package atguigu.cglib.demo2;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class HealthyKidInterceptor implements IMethordInterceptor{

	@Override
	public Object intercept(Object proxy, Method method, Object[] args, Method proxyMethod) {
		
		Kid kid = (Kid) proxy;
		if("eat".equals(method.getName())) {
			kid.washhand();
		}
		
		Object result = null;
		try {
			result = proxyMethod.invoke(proxy, args);
		} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			e.printStackTrace();
		}
		
		if("eat".equals(method.getName())) {
			kid.brushTeeth();
		}
		return result;
	}

}
